/**
 * 异常处理配置
 */

/**
 * 异常配置接口
 */
export interface ExceptionConfig {
  enableDetailedErrors: boolean;
  enableStackTrace: boolean;
  enableErrorStatistics: boolean;
  enableRequestLogging: boolean;
  sensitiveFields: string[];
  helpBaseUrl?: string;
}

/**
 * 默认异常处理配置
 */
export const defaultExceptionConfig: ExceptionConfig = {
  // 根据环境变量决定是否启用详细错误信息
  enableDetailedErrors: process.env.NODE_ENV !== "production",
  // 根据环境变量决定是否启用错误堆栈
  enableStackTrace: process.env.NODE_ENV === "development",
  // 启用错误统计
  enableErrorStatistics: true,
  // 启用请求参数记录
  enableRequestLogging: true,
  // 敏感字段列表，这些字段在日志中会被脱敏处理
  sensitiveFields: [
    "password",
    "token",
    "accessToken",
    "refreshToken",
    "authorization",
    "cookie",
    "session",
    "secret",
    "key",
    "apiKey",
    "privateKey",
    "publicKey",
    "signature",
    "hash",
    "salt",
    "nonce",
    "otp",
    "pin",
    "ssn",
    "creditCard",
    "bankAccount",
    "phone",
    "email",
    "idCard",
  ],
  // 帮助文档基础URL
  helpBaseUrl: process.env.HELP_BASE_URL || "https://docs.example.com/errors",
};

/**
 * 获取异常处理配置
 * @param customConfig 自定义配置
 * @returns 合并后的配置
 */
export function getExceptionConfig(customConfig?: Partial<ExceptionConfig>): ExceptionConfig {
  return {
    ...defaultExceptionConfig,
    ...customConfig,
  };
}
